﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Model
{
    public class QuestionConfig : IEntityTypeConfiguration<Question>
    {
        public void Configure(EntityTypeBuilder<Question> entity)
        {
            entity.ToTable("T_Question");
            entity.HasKey(q => q.Id);
            entity.Property(q => q.Q).HasMaxLength(2000).IsRequired();
            entity.Property(q => q.StudentId).IsRequired();
            entity.Property(q => q.Status).HasMaxLength(20).IsRequired();

            entity.HasOne(q => q.StudentInfo)  // 学生信息
                .WithMany()
                .HasForeignKey(q => q.StudentId)
                .OnDelete(DeleteBehavior.Cascade);  // 如果删除学生信息，对应的Question会被删除

            entity.HasMany(q => q.QuestionReplyList)  // 问题回复列表
                .WithOne()
                .HasForeignKey(q => q.QuestionId)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);
        }
    }
}
